<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

用户名：<input type="text" id="uname" name="username">
<span id="tipmsg"></span>


<script>
    document.querySelector("#uname").addEventListener("blur", () => {
      // alert("ajax")
        let xhr = new XMLHttpRequest();
        xhr.onreadystatechange=()=>{
            if(xhr.readyState==4){
                if(xhr.status==200){
                    document.getElementById("tipmsg").innerHTML=this.responseText;
                }else {
                   alert(xhr.status)
                }
            }
        }
        xhr.open("post","ajaxrequest",true);
        xhr.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
        let name = document.getElementById("uname").value;

        xhr.send("uname:"+name);

})
</script>
</body>
</html>